package com.cn.customer.housekeeping.housekeepingb.ui;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.cn.customer.housekeeping.housekeepingb.R;
import com.cn.customer.housekeeping.housekeepingb.bean.BaseResp;
import com.cn.customer.housekeeping.housekeepingb.bean.ProdctBean;
import com.cn.customer.housekeeping.housekeepingb.biz.personcenter.IUserLoginView;
import com.cn.customer.housekeeping.housekeepingb.biz.personcenter.InterfacePresenter;
import com.cn.customer.housekeeping.housekeepingb.ui.adapter.MyGridViewchoiceshopAdpter;
import com.cn.customer.housekeeping.housekeepingb.ui.base.BaseActivity;
import com.cn.customer.housekeeping.housekeepingb.util.Utils;

import java.util.ArrayList;
import java.util.List;


/***
 * 选择店铺
 */
public class ChoiceShopActivity extends BaseActivity implements IUserLoginView {

    private InterfacePresenter mInterfacePresenter;
    private GridView gv_business;
    private List<ProdctBean> listDatas;
    private  MyGridViewchoiceshopAdpter mMyGridViewchoiceshopAdpter;
    TextView tv_login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_choiceshop);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initViews() {
        mInterfacePresenter = new InterfacePresenter();
        gv_business = (GridView) findViewById(R.id.gv_business);
        tv_login = (TextView) findViewById(R.id.tv_login);
    }

    @Override
    public void initListeners() {
        tv_login.setOnClickListener(this);
        gv_business.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int select,
                                    long arg3) {
                mMyGridViewchoiceshopAdpter.changeStatus(select);//设置选中项
                mMyGridViewchoiceshopAdpter.notifyDataSetChanged();//更新列表
            }
        });
    }


    @Override
    public void initData() {
        listDatas = new ArrayList<ProdctBean>();
        for (int i = 0; i < 10; i++) {
            listDatas.add(new ProdctBean("菜单"+i, "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1878573216,1106833289&fm=27&gp=0.jpg"));
        }
        mMyGridViewchoiceshopAdpter= new MyGridViewchoiceshopAdpter(this, listDatas);
        gv_business.setAdapter(mMyGridViewchoiceshopAdpter);

    }

    @Override
    public void setHeader() {
        super.setHeader();
        rlTitle.setVisibility(View.VISIBLE);
        ivTopBack.setVisibility(View.GONE);
        tvTopTitle.setText("选择店铺类型");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_login:

                for (int i=0; i<mMyGridViewchoiceshopAdpter.lists.size(); i++) {
                    if(mMyGridViewchoiceshopAdpter.lists.get(i).isSelect()){

                    }
                }

//                Intent intent = new Intent();
//                intent.putExtra("select_result",  mFolderList.get(positions).getImageInfoList().get(position).getImageFile().getAbsolutePath());
//                setResult(RESULT_OK, intent);
//                finish();

                break;
        }
        super.onClick(v);
    }

    @Override
    public void onError(BaseResp s) {
        Utils.bequit(s,this);
    }

    @Override
    public void onSuccess(BaseResp s) {

    }

    @Override
    public void showLoading() {
        super.showLoading();
    }

    @Override
    public void hideLoading() {
        super.hideLoading();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
